package com.example.controller.exam;

import com.example.domain.exam.dto.ExamAddDTO;
import com.example.domain.exam.dto.ExamEditDTO;
import com.example.domain.exam.dto.ExamQueryDTO;
import com.example.domain.exam.dto.ExamQuestionDTO;
import com.example.domain.exam.vo.ExamDetailVO;
import com.example.server.exam.IExamService;
import oj.common.core.controller.BaseController;
import oj.common.core.domain.Result;
import oj.common.core.domain.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    @PostMapping("/add")
    public Result<String> add (@RequestBody ExamAddDTO examAddDTO) {
        return Result.success(examService.add(examAddDTO));
    }
    //增加竞赛当中的题目
    //在添加的时候，不要重复进行添加题目，这里还得对题目列表查询优化。
    @PostMapping("/question/add")
    public Result<Void> questionAdd(@RequestBody ExamQuestionDTO examQuestionDTO) {
        return toResult(examService.questionAdd(examQuestionDTO));
    }
    @DeleteMapping("/question/delete")
    public Result<Void> questionDelete(Long examId,Long questionId) {
        return toResult(examService.questionDelete(examId,questionId));
    }
    //删除竞赛
    @DeleteMapping("/delete")
    public Result<Void> delete(Long examId) {
        return toResult( examService.delete(examId));
    }

    //这是点击查询过后，然后进行显示页面的。
    //首先先去查询题目列表，然后再再去tb_exam_question表中查询相应的题目
    @GetMapping("/detail")
    public Result<ExamDetailVO> detail(Long examId) {
        return Result.success(examService.detail(examId));
    }

    //基本信息的编辑
    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toResult(examService.edit(examEditDTO));
    }

    @PutMapping("/publish")
    public Result<Void> publish(Long examId) {
        return toResult(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    public Result<Void> cancelPublish(Long examId) {
        return toResult(examService.cancelPublish(examId));
    }
}
